package cn.itcast.bos.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import cn.itcast.bos.web.action.common.BaseAction;

@ParentPackage("json-default")
@Controller
@Actions
@Scope("prototype")
@Namespace("/")
public class StandardAction extends BaseAction<Standard> {
	
	@Autowired
	private StandardService standardService;
	
	//添加收派标准
	@Action(value="standard_save",
			results={@Result(name="success",location="/pages/base/standard.html",type="redirect")})
	public String save(){
		
		standardService.save(model);
		return SUCCESS;
	}
	
	//收派标准分页查询
	@Action(value="standard_pageQuery",
			results={@Result(name="success",type="json")})
	public String pageQuery(){
		//调用业务层查询数据
		Pageable pageable = new PageRequest(page-1, rows);
		
		Page<Standard> pageData = standardService.findPageDataa(pageable);
		
		pushPageDataToValueStack(pageData);
		
		return SUCCESS;
		
	}
	
	@Action(value="standard_findAll",results={@Result(name="success",type="json")})
	public String findAll(){
		List<Standard> standards = standardService.findAll();
		ActionContext.getContext().getValueStack().push(standards);
		return SUCCESS;
	}
	
	
}
